#include "MenuManager.h"
#include "MenuBase.h"
#include "Settings/Settings.h"
#include "Systems/Memory.h"

#include "SFML/Graphics.hpp"

struct MenuManager::MenuManagerImpl
{
	GameSettings* m_gs;
	MenuBase* m_currentMenu;
	MenuBase* m_previousMenu;
	sf::RenderWindow* m_mainWindow;
};

MenuManager::MenuManager()
{
	m_impl = Z_NEW MenuManagerImpl;
}

MenuManager::~MenuManager()
{
	Z_DELETE(m_impl);
}

void MenuManager::Update(const float i_elapsedTime)
{
	if (m_impl->m_currentMenu)
		m_impl->m_currentMenu->Update(i_elapsedTime);
}

void MenuManager::Draw(const float i_elapsedTime)
{
	if (m_impl->m_currentMenu)
		m_impl->m_currentMenu->Draw(i_elapsedTime);
}

void MenuManager::SetNextMenu(MenuBase* const i_nextMenu)
{
	m_impl->m_previousMenu = m_impl->m_currentMenu;
	m_impl->m_currentMenu = i_nextMenu;
}

void MenuManager::GoBack()
{
	m_impl->m_currentMenu = m_impl->m_previousMenu;
}

void MenuManager::Init(GameSettings* i_gs)
{
	m_impl->m_gs = i_gs;


	m_impl->m_mainWindow = Z_NEW sf::RenderWindow(sf::VideoMode(m_impl->m_gs->mainWindowWidth, m_impl->m_gs->mainWindowHeight),
							m_impl->m_gs->gameName, m_impl->m_gs->mainWindowfullScreen ? sf::Style::Fullscreen : sf::Style::Close);

	m_impl->m_mainWindow->UseVerticalSync(true);
	m_impl->m_mainWindow->SetFramerateLimit(0);
}
